]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
modalDialog: do not launch disabled button actions
authorStéphane Démurget <stephane.demurget@free.fr>
Sun, 18 Nov 2012 20:29:46 +0000 (21:29 +0100)
committerStéphane Démurget <stephane.demurget@free.fr>
Tue, 20 Nov 2012 20:08:37 +0000 (21:08 +0100)
The "Sign In" button of the login dialog has its look disabled when the
entry is empty, but it can still be triggered by the Enter key.

This fixes the modal dialog so it does not trigger the action of an
insensitive button, and also means we do not need to connect to the
"activate" signal of the entry anymore.

https://bugzilla.gnome.org/show_bug.cgi?id=687113

js/ui/modalDialog.js
js/ui/unlockDialog.js

index 2ee2579e5645c5ec0243c0b6e363fc6417173419..065ce9e9be2da9c3e90f3b048b5fe9e067776779 100644 (file)
@@ -58,7 +58,7 @@ const ModalDialog = new Lang.Class({
 
         this._group.connect('destroy', Lang.bind(this, this._onGroupDestroy));
 
-        this._actionKeys = {};
+        this._buttonKeys = {};
         this._group.connect('key-release-event', Lang.bind(this, this._onKeyReleaseEvent));
 
         this._backgroundBin = new St.Bin();
@@ -113,13 +113,9 @@ const ModalDialog = new Lang.Class({
         this._group.destroy();
     },
 
-    setActionKey: function(key, action) {
-        this._actionKeys[key] = action;
-    },
-
     clearButtons: function() {
         this.buttonLayout.destroy_all_children();
-        this._actionKeys = {};
+        this._buttonKeys = {};
     },
 
     setButtons: function(buttons) {
@@ -139,12 +135,11 @@ const ModalDialog = new Lang.Class({
             else
                 x_alignment = St.Align.MIDDLE;
 
-            let button = this.addButton(buttonInfo, { expand: true,
-                                                      x_fill: false,
-                                                      y_fill: false,
-                                                      x_align: x_alignment,
-                                                      y_align: St.Align.MIDDLE });
-            buttonInfo.button = button;
+            this.addButton(buttonInfo, { expand: true,
+                                         x_fill: false,
+                                         y_fill: false,
+                                         x_align: x_alignment,
+                                         y_align: St.Align.MIDDLE });
         }
     },
 
@@ -154,27 +149,31 @@ const ModalDialog = new Lang.Class({
         let key = buttonInfo['key'];
         let isDefault = buttonInfo['default'];
 
-        if (isDefault && !key) {
-            this._actionKeys[Clutter.KEY_KP_Enter] = action;
-            this._actionKeys[Clutter.KEY_ISO_Enter] = action;
-            key = Clutter.KEY_Return;
-        }
+        let keys;
+
+        if (key)
+            keys = [key];
+        else if (isDefault)
+            keys = [Clutter.KEY_Return, Clutter.KEY_KP_Enter, Clutter.KEY_ISO_Enter];
+        else
+            keys = [];
 
         let button = new St.Button({ style_class: 'modal-dialog-button',
                                      reactive:    true,
                                      can_focus:   true,
                                      label:       label });
-
         button.connect('clicked', action);
 
+        buttonInfo['button'] = button;
+
         if (isDefault)
             button.add_style_pseudo_class('default');
 
         if (!this._initialKeyFocusDestroyId)
             this._initialKeyFocus = button;
 
-        if (key)
-            this._actionKeys[key] = action;
+        for (let i in keys)
+            this._buttonKeys[keys[i]] = buttonInfo;
 
         this.buttonLayout.add(button, layoutInfo);
 
@@ -183,9 +182,15 @@ const ModalDialog = new Lang.Class({
 
     _onKeyReleaseEvent: function(object, event) {
         let symbol = event.get_key_symbol();
-        let action = this._actionKeys[symbol];
+        let buttonInfo = this._buttonKeys[symbol];
+
+        if (!buttonInfo)
+            return false;
+
+        let button = buttonInfo['button'];
+        let action = buttonInfo['action'];
 
-        if (action) {
+        if (action && button.reactive) {
             action();
             return true;
         }
index 9996385a30422e4b37dafe82dd12d96af0dc0ab8..98ff22aaca8be1cb442f6ab413847e2c73f70d56 100644 (file)
@@ -151,7 +151,6 @@ const UnlockDialog = new Lang.Class({
         this._promptEntry.clutter_text.set_password_char('\u25cf');
         ShellEntry.addContextMenu(this._promptEntry, { isPassword: true });
         this.setInitialKeyFocus(this._promptEntry);
-        this._promptEntry.clutter_text.connect('activate', Lang.bind(this, this._doUnlock));
         this._promptEntry.clutter_text.connect('text-changed', Lang.bind(this, function() {
             this._updateOkButtonSensitivity(this._promptEntry.text.length > 0);
         }));